package com.veryUsedCar.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.veryUsedCar.mapper.UserMapper;
import com.veryUsedCar.po.User;
import com.veryUsedCar.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public void addUser(User user) {
        userMapper.insert(user);
    }

    @Override
    public void updateUser(User user) {
        userMapper.updateById(user);
    }

    @Override
    public User findById(Long uid) {
        return userMapper.selectById(uid);
    }

    @Override
    public void deleteById(Long uid) {
        userMapper.deleteById(uid);
    }

    @Override
    public User findUserByName(String uname) {
        LambdaQueryWrapper<User> query = new LambdaQueryWrapper<>();
        query.eq(User::getUname,uname);
        List<User> users = userMapper.selectList(query);
        if (users != null && !users.isEmpty()){
            User user = users.get(0);
            return user;
        }
        return null;
    }
}
